
//1385.两个数组间的距离值
class Solution {
public:
    int findTheDistanceValue(vector<int>& arr1, vector<int>& arr2, int d) {
        //对arr2进行排序，枚举arr1判断arr2时候满足条件
        //arr2[j]-d<=arr1[i]<=arr2[j]+d
        //arr1[i]-d<=arr[2]<=arr1[i]+d

        int n=arr1.size();
        int m=arr2.size(),ret=0;
        sort(arr2.begin(),arr2.end());

        for(int i=0;i<n;i++)
        {
            int pos=lower_bound(arr2.begin(),arr2.end(),arr1[i]-d)-arr2.begin();  //找到最小的一个
            if(pos==m||arr2[pos]>arr1[i]+d) ret++;    //判断是否在区间外
        }
        return ret;
    }
};